package com.nut.config;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-05-09 17:08
 * @ Description : 自定义登录成功跳转页面处理器Handler
 */
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler
{

    private final String url;

    public MyAuthenticationSuccessHandler(String url)
    {
        this.url = url;
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest,
                                        HttpServletResponse httpServletResponse,
                                        Authentication authentication)
            throws IOException, ServletException
    {
        //System.out.println(authentication.getAuthorities());
        //System.out.println(authentication.getCredentials());
        //System.out.println(authentication.getDetails());
        //System.out.println(authentication.getPrincipal());
        httpServletResponse.sendRedirect(url);
    }

}
